import { Byte } from '../../api/io/Byte';
import { HashMap } from '../../api/struct/HashMap';


export const enum E_CDFunction {
	/**编号(主键)//不要随便改id会影响到引导*/
	id,
	/**排序*/
	order,
	/**解锁条件id*/
	unlockid,
	/**名称*/
	name,
	/**系统描述*/
	desc,
	/**获取描述*/
	accessDesc,
	/**跳转页面*/
	jumpid,
	/**图集目录*/
	set,
	/**图标名称--不填不显示*/
	icon,
	/**是否有功能开启动画*/
	unlockAct,

	/**枚举数量*/
	EnumCount
}



export class CDFunction{
	/**编号(主键)//不要随便改id会影响到引导*/
	public id: number;
	/**排序*/
	public order: number;
	/**解锁条件id*/
	public unlockid: number;
	/**名称*/
	public name: number;
	/**系统描述*/
	public desc: number;
	/**获取描述*/
	public accessDesc: number;
	/**跳转页面*/
	public jumpid: number;
	/**图集目录*/
	public set: string;
	/**图标名称--不填不显示*/
	public icon: string;
	/**是否有功能开启动画*/
	public unlockAct: number;


	/**获取属性值*/
	public getAttr(idx: number): any {
		switch(idx) { 
			default: return;
			case E_CDFunction.id: return this.id;
			case E_CDFunction.order: return this.order;
			case E_CDFunction.unlockid: return this.unlockid;
			case E_CDFunction.name: return this.name;
			case E_CDFunction.desc: return this.desc;
			case E_CDFunction.accessDesc: return this.accessDesc;
			case E_CDFunction.jumpid: return this.jumpid;
			case E_CDFunction.set: return this.set;
			case E_CDFunction.icon: return this.icon;
			case E_CDFunction.unlockAct: return this.unlockAct;
		}
	}



	/**设置属性值*/
	public setAttr(idx: number, v: any): void {
		switch(idx) { 
			default: break;
			case E_CDFunction.id: this.id = v; break;
			case E_CDFunction.order: this.order = v; break;
			case E_CDFunction.unlockid: this.unlockid = v; break;
			case E_CDFunction.name: this.name = v; break;
			case E_CDFunction.desc: this.desc = v; break;
			case E_CDFunction.accessDesc: this.accessDesc = v; break;
			case E_CDFunction.jumpid: this.jumpid = v; break;
			case E_CDFunction.set: this.set = v; break;
			case E_CDFunction.icon: this.icon = v; break;
			case E_CDFunction.unlockAct: this.unlockAct = v; break;
		}
	}


	/**数据*/
	public static datas: HashMap<number, CDFunction> = new HashMap<number, CDFunction>();



	/**加载数据*/
	public static load(byte: Byte): void{
		const size = byte.readInt32();
		const list : CDFunction[] = [];
		let i :number;

		for (i = 0; i < size; i++) {
			list[i] = new CDFunction();
		}
		for (i = 0; i < size; i++) {
			list[i].id = byte.readInt32();
			this.datas.put(list[i].id, list[i]);
		}
		for (i = 0; i < size; i++) {
			list[i].order = byte.readInt32();
		}
		for (i = 0; i < size; i++) {
			list[i].unlockid = byte.readInt32();
		}
		for (i = 0; i < size; i++) {
			list[i].name = byte.readInt32();
		}
		for (i = 0; i < size; i++) {
			list[i].desc = byte.readInt32();
		}
		for (i = 0; i < size; i++) {
			list[i].accessDesc = byte.readInt32();
		}
		for (i = 0; i < size; i++) {
			list[i].jumpid = byte.readInt32();
		}
		for (i = 0; i < size; i++) {
			list[i].set = byte.readString();
		}
		for (i = 0; i < size; i++) {
			list[i].icon = byte.readString();
		}
		for (i = 0; i < size; i++) {
			list[i].unlockAct = byte.readInt32();
		}
	}


	/** 获取数据*/
	public static getData(id: number): CDFunction{
		return this.datas ? this.datas.get(id) : null;
	}
}
